export default {
    //校验数字(name:校验字段的名字，id:当前组件的id名字，form:当前字段所在的FORM名字，type:当前字段不符合规则后清空的值==>数字:0;字符串:'')
    checkNum: function (_name, _id, _form, _value, _this){
        let reg = /^[1-9]\d*$/;
        if (_form[_name]) {
            if (new RegExp(reg).test(_form[_name]) == false) {
                document.getElementById(_id).value = "";
                _form[_name] = _value;
                document.getElementById(_id).focus();
                _this.$message({
                    message: '请输入正确的数字格式',
                    type: 'info'
                });
            }
        }
    },
    //格式化时间(date:Date类型时间，pattern:时间格式 如:yyyy-MM-dd hh:mm:ss)
    formatDate: function (date, pattern) {
        let SIGN_REGEXP = /([yMdhsm])(\1*)/g;
        let DEFAULT_PATTERN = 'yyyy-MM-dd';
        pattern = pattern || DEFAULT_PATTERN;
        return pattern.replace(SIGN_REGEXP, function ($0) {
            switch ($0.charAt(0)) {
                case 'y': return padding(date.getFullYear(), $0.length);
                case 'M': return padding(date.getMonth() + 1, $0.length);
                case 'd': return padding(date.getDate(), $0.length);
                case 'w': return date.getDay() + 1;
                case 'h': return padding(date.getHours(), $0.length);
                case 'm': return padding(date.getMinutes(), $0.length);
                case 's': return padding(date.getSeconds(), $0.length);
            }
        });
    },
}
function padding(s, len) {
    var len = len - (s + '').length;
    for (var i = 0; i < len; i++) { s = '0' + s; }
    return s;
};